package org.sith.taskrunner.engine;


import org.sith.taskrunner.api.RunType;
import org.sith.taskrunner.api.TaskRegisterResult;
import org.sith.taskrunner.api.TaskRunRequest;

import java.util.Comparator;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;

public class TaskRunnerQueue {

    private static TaskRunnerQueue ourInstance = new TaskRunnerQueue();

    private final Set<TaskRunRequest> queue;


    private final Stack<TaskRunRequest> stack;

    public static TaskRunnerQueue getInstance() {
        return ourInstance;
    }

    private TaskRunnerQueue() {
        stack = new Stack<TaskRunRequest>();
        queue = new TreeSet<TaskRunRequest>();
    }

    public TaskRegisterResult registerTask(TaskRunRequest request) {

        switch (request.getRunType()) {
            case IMMEDIATELY: {
                stack.add(request);
            }
            break;
            case RUN_ON_DATE: {
                throw new IllegalStateException("Not implemented yet");
            }
//            break;
            default: {
            }
            break;
        }


        return new TaskRegisterResult();
    }

    //TODO think about synchronized
    public synchronized TaskRunRequest getNextRequest() {
        return stack.pop();
    }


}
